package com.zackeus.mvvm.api.response;

import androidx.annotation.IntDef;
import androidx.annotation.StringDef;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.net.HttpURLConnection;

/**
 * http 响应状态
 * @name: ResponseStatusCodes
 * @author: zz
 * @date: 2022/9/2
 */

public class ResponseStatus {

    @Target({ElementType.FIELD, ElementType.PARAMETER})
    @Retention(RetentionPolicy.SOURCE)
    @IntDef({HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_UNAUTHORIZED,
            HttpURLConnection.HTTP_FORBIDDEN, HttpURLConnection.HTTP_NOT_FOUND,
            HttpURLConnection.HTTP_CLIENT_TIMEOUT, HttpURLConnection.HTTP_SERVER_ERROR,
            HttpURLConnection.HTTP_UNAVAILABLE
    })
    private  @interface CODE{}

    @Target({ElementType.FIELD, ElementType.PARAMETER})
    @Retention(RetentionPolicy.SOURCE)
    @StringDef({HTTP_OK, HTTP_UNAUTHORIZED, HTTP_FORBIDDEN, HTTP_NOT_FOUND, HTTP_CLIENT_TIMEOUT,
            HTTP_SERVER_ERROR, HTTP_UNAVAILABLE
    })
    private  @interface MSG{}

    private @CODE
    final int code;

    private @MSG
    final String msg;

    public ResponseStatus(@CODE int code, @MSG String msg) {
        this.code = code;
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    /* 2** */
    public static final String HTTP_OK = "success";

    /* 4** */
    public static final String HTTP_UNAUTHORIZED = "操作未授权";
    public static final String HTTP_FORBIDDEN = "请求被拒绝";
    public static final String HTTP_NOT_FOUND = "资源不存在";
    public static final String HTTP_CLIENT_TIMEOUT = "请求超时";

    /* 5** */
    public static final String HTTP_SERVER_ERROR = "内部错误";
    public static final String HTTP_UNAVAILABLE = "服务不可用";

}
